﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EQual.MainModule.Documents.Presenters
{
    public class VersionsPresenter
    {
        public object ActiveItem {get;set;}

        public EventHandler<Microsoft.Practices.Composite.Events.DataEventArgs<DataAccesLayer.Document>> DocumentSavedHandler()
        {
            return delegate(object sender, Microsoft.Practices.Composite.Events.DataEventArgs<DataAccesLayer.Document> e)
            {
                DisplayDocumentSaveDialog();
            };
        }

        public EventHandler<Microsoft.Practices.Composite.Events.DataEventArgs<object>> UpdateDocument()
        {
            return delegate(object s, Microsoft.Practices.Composite.Events.DataEventArgs<object> e)
            {
                DisplayVersionDialog();
            };
        }

        public EventHandler<Microsoft.Practices.Composite.Events.DataEventArgs<object>> UpdateVersion()
        {
            return delegate(object s, Microsoft.Practices.Composite.Events.DataEventArgs<object> e)
            {
                RequestNewVersionUpdate(e.Value);
            };
        }

        protected virtual void RequestNewVersionUpdate(object version)
        {
            new DataAccesLayer.EQualDataLayerFactory().GetDocumentAccesLayer().AddNewDocumentVersion(ActiveItem,version);
        }

        protected virtual void DisplayVersionDialog()
        {
            Views.VersionSaveDialog  VersionSaveDialog = new Views.VersionSaveDialog ();
            VersionSaveDialog.OnVersionUpdated += UpdateVersion();
            VersionSaveDialog.ShowDialog();
        }

        protected virtual  void DisplayDocumentSaveDialog()
        {
            Views.DocumentSaveDialog DocumentSaveDialog = new Views.DocumentSaveDialog();
            DocumentSaveDialog.OnDocumentUpdated += UpdateDocument();
            DocumentSaveDialog.ShowDialog();
        }


    }
}
